<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title> UDT Reference</title>
<link rel="stylesheet" href="udtdoc.css" type="text/css" />
</head>

<body>
<div class="ref_head">&nbsp;UDT Reference: Functions</div>

<h4 class="func_name"><strong>getsockopt</strong></h4>
<h4 class="func_name"><strong>setsockopt</strong></h4>
<p>The <b>getsockopt</b> and <b>setsockopt</b> methods read and set UDT options, respectively.</p>

<div class="code">
  int getsockopt(<br />
  &nbsp; UDTSOCKET <font color="#FFFFFF">u</font>,<br />
  &nbsp; int <font color="#FFFFFF">level</font>,<br />
  &nbsp; SOCKOPT <font color="#FFFFFF">optname</font>,<br />
  &nbsp; char* <font color="#FFFFFF">optval</font>,<br />
  &nbsp; int* <font color="#FFFFFF">optlen</font><br />
    );  <br><br />
  int setsockopt(<br />
  &nbsp; UDTSOCKET <font color="#FFFFFF">u</font>,<br />
  &nbsp; int <font color="#FFFFFF">level</font>,<br />
  &nbsp; SOCKOPT <font color="#FFFFFF">optname</font>,<br />
  &nbsp; const char* <font color="#FFFFFF">optval</font>,<br />
  &nbsp; int <font color="#FFFFFF">optlen</font><br />
    );
</div>

<h5>Parameters</h5>
<dl>
  <dt><i>u</i></dt>
  <dd>[in] Descriptor identifying a UDT socket.</dd>
  <dt><em>level</em></dt>
  <dd>[in] Unused. For compatibility only.</dd>
  <dt><em>optName</em></dt>
  <dd>[in] The enum name of UDT option. The names and meanings are listed in the table below.</dd>
  <dt>&nbsp;</dt>
  <table width="100%" border="1" cellpadding="2" cellspacing="0" bordercolor="#CCCCCC">
    <tr>
      <td width="12%" class="table_headline"><strong>Name</strong></td>
      <td width="9%" class="table_headline"><strong>Type</strong></td>
      <td width="27%" class="table_headline"><strong>Meaning</strong></td>
      <td width="52%" class="table_headline"><strong>Comment</strong></td>
    </tr>
    <tr>
      <td>UDT_MSS</td>
      <td>int</td>
      <td>Maximum packet size (bytes).</td>
      <td>Including all UDT, UDP, and IP headers. Default 1500 bytes.</td>
    </tr>
    <tr>
      <td>UDT_SNDSYN</td>
      <td>bool</td>
      <td>Synchronization mode of data sending.</td>
      <td>true for blocking sending; false for non-blocking sending. Default true.</td>
    </tr>
    <tr>
      <td>UDT_RCVSYN</td>
      <td>bool</td>
      <td>Synchronization mode for receiving.</td>
      <td>true for blocking receiving; false for non-blocking receiving. Default true.</td>
    </tr>
    <tr>
      <td>UDT_CC</td>
      <td>CCCFactory*<br>CCC**</td>
      <td>User defined congestion control algorithm.</td>
      <td><i>optval</i> is a pointer to a CCC Factory class instance (for setsockopt).<br><i>optval</i> is a pointer of pointer to a CCC class instance (for getsockopt).</td>
    </tr>
    <tr>
      <td>UDT_FC</td>
      <td>int</td>
      <td>Maximum window size (packets)</td>
      <td>Default 25600. Do NOT change this unless you know what you are doing. Must change this before modifying the buffer sizes. </td>
    </tr>
    <tr>
      <td>UDT_SNDBUF</td>
      <td>int</td>
      <td>UDT sender buffer size limit (bytes)</td>
      <td>Default 10MB (10240000).</td>
    </tr>
    <tr>
      <td>UDT_RCVBUF</td>
      <td>int</td>
      <td>UDT receiver buffer size limit (bytes)</td>
      <td>Default 10MB (10240000).</td>
    </tr>
    <tr>
      <td>UDP_SNDBUF</td>
      <td>int</td>
      <td>UDP socket sender buffer size (bytes)</td>
      <td>Default 1MB (1024000).</td>
    </tr>
    <tr>
      <td>UDP_RCVBUF</td>
      <td>int</td>
      <td>UDP socket receiver buffer size (bytes)</td>
      <td>Default 1MB (1024000).</td>
    </tr>
    <tr>
      <td>UDT_LINGER</td>
      <td>linger</td>
      <td>Linger time on close().</td>
      <td>Default 180 seconds.</td>
    </tr>
    <tr>
      <td>UDT_RENDEZVOUS</td>
      <td>bool</td>
      <td>Rendezvous connection setup.</td>
      <td>Default false (no rendezvous mode).</td>
    </tr>
    <tr>
      <td>UDT_SNDTIMEO</td>
      <td>int</td>
      <td>Sending call timeout (milliseconds).</td>
      <td>Default -1 (infinite).</td>
    </tr>
    <tr>
      <td>UDT_RCVTIMEO</td>
      <td>int</td>
      <td>Receiving call timeout (milliseconds).</td>
      <td>Default -1 (infinite).</td>
    </tr>
    <tr>
      <td>UDT_REUSEADDR</td>
      <td>bool</td>
      <td>Reuse an existing address or create a new one.</td>
      <td>Default true (reuse).</td>
    </tr>
    <tr>
      <td>UDT_MAXBW</td>
      <td>int64_t</td>
      <td>Maximum bandwidth that one single UDT connection can use (bytes per second).</td>
      <td>Default -1 (no upper limit).</td>
    </tr>
    <tr>
      <td>UDT_STATE</td>
      <td>int32_t</td>
      <td>Current status of the UDT socket.</td>
      <td>Read only.</td>
    </tr>
    <tr>
      <td>UDT_EVENT</td>
      <td>int32_t</td>
      <td>The EPOLL events available to this socket.</td>
      <td>Read only.</td>
    </tr>
    <tr>
      <td>UDT_SNDDATA</td>
      <td>int32_t</td>
      <td>Size of pending data in the sending buffer.</td>
      <td>Read only.</td>
    </tr>
    <tr>
      <td>UDT_RCVDATA</td>
      <td>int32_t</td>
      <td>Size of data available to read, in the receiving buffer.</td>
      <td>Read only.</td>
    </tr>
  </table>

  <dt><em>optval</em></dt>
  <dd>[in (set), out (get)] Pointer to the value of UDT option.</dd>
  <dt><em>optlen</em></dt>
  <dd>[in (set), in/out (get)] Pointer to the length of <i>optval</i>.</dd>
</dl>

<h5>Return Value</h5>
<p>On success, 0 is returned and proper UDT option is set or read; otherwise UDT::ERROR is returned and the specific error information can be retrieved using <a 
href="error.htm">getlasterror</a>.</p>

<table width="100%" border="1" cellpadding="2" cellspacing="0" bordercolor="#CCCCCC">
  <tr>
    <td width="17%" class="table_headline"><strong>Error Name</strong></td>
    <td width="17%" class="table_headline"><strong>Error Code</strong></td>
    <td width="83%" class="table_headline"><strong>Comment</strong></td>
  </tr>
  <tr>
    <td>EBOUNDSOCK</td>
    <td>5001</td>
    <td>the sepecific option cannot be set on a bound socket.</td>
  </tr>
  <tr>
    <td>ECONNSOCK</td>
    <td>5002</td>
    <td>the specific option cannot be set on a connected socket.</td>
  </tr>
  <tr>
    <td>EINVPARAM</td>
    <td>5003</td>
    <td>the option value or length is invalid.</td>
  </tr>
  <tr>
    <td>EINVSOCK</td>
    <td>5004</td>
    <td><i>u</i> is an invalid UDT socket.</td>
  </tr>
</table>

<h5>Description</h5>
<p>the <strong>setsockopt</strong> method sets the UDT option <i>optName</i> with the value of <i>optval</i>. The parameter of <i>optlen</i> is checked to verify the goodness of the 
option value. Not all options can be set at any state of UDT. In fact, most options must be set before <strong>bind</strong> or <strong>connect</strong> is called, because these values 
are necessary to initialize certain data structures when a UDT connection is created.</p>

<p>The <strong>getsockopt</strong> method reads the current option value. The value is written into the buffer pointed by <i>optval</i> and the length is returned in <i>optlen</i>.</p>

<h5>Example</h5>
To send data sending in non-blocking mode, the code can be like:
<div class="code">
UDTSOCKET u;<br>
...<br>
bool block = false;<br>
UDT::setsockopt(u, 0, UDT_SNDSYN, &block, sizeof(bool));
</div>

<h5>See Also</h5>
<p><strong><a href="t-config.htm">Configure UDT Options</a></strong></p>
<p>&nbsp;</p>

</body>
</html>
